package ch08 {
	/**
	 * 缠绕
	 * @author jianping.shenjp
	 */
	import flash.display.Graphics;
	import flash.display.GraphicsPathCommand;
	import flash.display.GraphicsPathWinding;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;

	[SWF(backgroundColor=0xffffff)]
	public class WindingDemo extends Sprite {
		private var commands:Vector.<int> = new Vector.<int>();
		private var data1:Vector.<Number> = new Vector.<Number>();
		private var data2:Vector.<Number> = new Vector.<Number>();

		public function WindingDemo(){
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			commands.push(GraphicsPathCommand.MOVE_TO);
			commands.push(GraphicsPathCommand.LINE_TO);
			commands.push(GraphicsPathCommand.LINE_TO);
			commands.push(GraphicsPathCommand.LINE_TO);
			commands.push(GraphicsPathCommand.LINE_TO);
			data1.push(150, 100);
			data1.push(200, 100);
			data1.push(200, 250);
			data1.push(150, 250);
			data1.push(150, 100);
			//顺时针
			data2.push(100, 150);
			data2.push(250, 150);
			data2.push(250, 200);
			data2.push(100, 200);
			data2.push(100, 150);
			//逆时针
			//data2.push(100, 150);
			//data2.push(100, 200);
			//data2.push(250, 200);
			//data2.push(250, 150);
			//data2.push(100, 150);
			var g:Graphics = graphics;
			g.beginFill(0xff0000);
			/**
			 * EVEN_ODD(奇偶缠绕类型)不填充交叉区域，NON_ZERO(非零缠绕类型) 就填充。"
			 * 还记得正/负向缠绕吗？当指定缠绕为 NON_ZERO 时，Flash 会根据重叠路径的
			 * 缠绕来决定如何处理交叉区域，规则如下：
			 * 如果两个路径的缠绕一致（都为正或者负），则填充交叉区域。
			 * 如果两个路径的缠绕不一致（一正一负），则不填充交叉区域。
			 */
			g.drawPath(commands, data1, GraphicsPathWinding.NON_ZERO);
			g.drawPath(commands, data2, GraphicsPathWinding.NON_ZERO);
			g.endFill();
		}
	}

}